<!DOCTYPE HTML>
<html lang="en" class="sidebar-visible no-js light">
    <head>
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>文档 - The Rust Rand Book</title>
        
        


        <!-- Custom HTML head -->
        


        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="Extended documentation for Rust&#x27;s Rand lib">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff" />

        
        <link rel="icon" href="favicon.svg">
        
        
        <link rel="shortcut icon" href="favicon.png">
        
        <link rel="stylesheet" href="css/variables.css">
        <link rel="stylesheet" href="css/general.css">
        <link rel="stylesheet" href="css/chrome.css">
        <link rel="stylesheet" href="css/print.css" media="print">

        <!-- Fonts -->
        <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
        
        <link rel="stylesheet" href="fonts/fonts.css">
        

        <!-- Highlight.js Stylesheets -->
        <link rel="stylesheet" href="highlight.css">
        <link rel="stylesheet" href="tomorrow-night.css">
        <link rel="stylesheet" href="ayu-highlight.css">

        <!-- Custom theme stylesheets -->
        

        
    </head>
    <body>
        <!-- Provide site root to javascript -->
        <script type="text/javascript">
            var path_to_root = "";
            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
        </script>

        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script type="text/javascript">
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script type="text/javascript">
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
            if (theme === null || theme === undefined) { theme = default_theme; }
            var html = document.querySelector('html');
            html.classList.remove('no-js')
            html.classList.remove('light')
            html.classList.add(theme);
            html.classList.add('js');
        </script>

        <!-- Hide / unhide sidebar before it is displayed -->
        <script type="text/javascript">
            var html = document.querySelector('html');
            var sidebar = 'hidden';
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            }
            html.classList.remove('sidebar-visible');
            html.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <div class="sidebar-scrollbox">
                <ol class="chapter"><li class="chapter-item expanded affix "><a href="intro.html">介绍</a></li><li class="chapter-item expanded "><a href="guide-start.html"><strong aria-hidden="true">1.</strong> 入门指南</a></li><li class="chapter-item expanded "><a href="crates.html"><strong aria-hidden="true">2.</strong> crate 和特性</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="crates-rand.html"><strong aria-hidden="true">2.1.</strong> 随机加密(co)</a></li><li class="chapter-item expanded "><a href="crates-gen.html"><strong aria-hidden="true">2.2.</strong> 随机信号生成器</a></li></ol></li><li class="chapter-item expanded "><a href="guide.html"><strong aria-hidden="true">3.</strong> 指南</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="guide-data.html"><strong aria-hidden="true">3.1.</strong> 随机数据</a></li><li class="chapter-item expanded "><a href="guide-gen.html"><strong aria-hidden="true">3.2.</strong> 生成器类型</a></li><li class="chapter-item expanded "><a href="guide-rngs.html"><strong aria-hidden="true">3.3.</strong> 随机数生成器(RNGs)</a></li><li class="chapter-item expanded "><a href="guide-seeding.html"><strong aria-hidden="true">3.4.</strong> 为随机数生成器置种</a></li><li class="chapter-item expanded "><a href="guide-values.html"><strong aria-hidden="true">3.5.</strong> 随机值</a></li><li class="chapter-item expanded "><a href="guide-dist.html"><strong aria-hidden="true">3.6.</strong> 各种分布方式</a></li><li class="chapter-item expanded "><a href="guide-seq.html"><strong aria-hidden="true">3.7.</strong> 序列</a></li><li class="chapter-item expanded "><a href="guide-err.html"><strong aria-hidden="true">3.8.</strong> 错误处理</a></li></ol></li><li class="chapter-item expanded "><a href="portability.html"><strong aria-hidden="true">4.</strong> 可移植性</a></li><li class="chapter-item expanded "><a href="update.html"><strong aria-hidden="true">5.</strong> 更新</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="update-0.5.html"><strong aria-hidden="true">5.1.</strong> 更新到 0.5</a></li><li class="chapter-item expanded "><a href="update-0.6.html"><strong aria-hidden="true">5.2.</strong> 更新到 0.6</a></li><li class="chapter-item expanded "><a href="update-0.7.html"><strong aria-hidden="true">5.3.</strong> 更新到 0.7</a></li></ol></li><li class="chapter-item expanded "><a href="contributing.html"><strong aria-hidden="true">6.</strong> 贡献</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="contrib-doc.html" class="active"><strong aria-hidden="true">6.1.</strong> 文档</a></li><li class="chapter-item expanded "><a href="contrib-scope.html"><strong aria-hidden="true">6.2.</strong> Scope</a></li><li class="chapter-item expanded "><a href="contrib-test.html"><strong aria-hidden="true">6.3.</strong> 测试</a></li><li class="chapter-item expanded "><a href="contrib-bench.html"><strong aria-hidden="true">6.4.</strong> 基准</a></li></ol></li></ol>
            </div>
            <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
        </nav>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                
                <div id="menu-bar-hover-placeholder"></div>
                <div id="menu-bar" class="menu-bar sticky bordered">
                    <div class="left-buttons">
                        <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                            <i class="fa fa-bars"></i>
                        </button>
                        <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                            <i class="fa fa-paint-brush"></i>
                        </button>
                        <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                            <li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                        </ul>
                        
                        <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                            <i class="fa fa-search"></i>
                        </button>
                        
                    </div>

                    <h1 class="menu-title">The Rust Rand Book</h1>

                    <div class="right-buttons">
                        <a href="print.html" title="Print this book" aria-label="Print this book">
                            <i id="print-button" class="fa fa-print"></i>
                        </a>
                        
                    </div>
                </div>

                
                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" name="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>
                

                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script type="text/javascript">
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <blockquote>
<p><a href="https://github.com/rust-random/book/blob/master/src/contrib-doc.md">contrib-doc.md</a><br />
commit: 3edaf6ff2d931b366c3f8dd1bae5cf523aa9672c <br />
本章译文最后维护日期：2020-12-2</p>
</blockquote>
<h1><a class="header" href="#documentation" id="documentation">Documentation</a></h1>
<h1><a class="header" href="#文档" id="文档">文档</a></h1>
<h3><a class="header" href="#style" id="style">Style</a></h3>
<h3><a class="header" href="#风格" id="风格">风格</a></h3>
<p>所有的文档都是英文的，并且最好没有特定的方言。</p>
<p>这些文档应该可以被多种受众访问：既有经验丰富的 Rustaceans，也有相对的新手，有统计建模或密码学方面的资深人士，也有对这门学科不熟悉的人。
因为通常不可能写出适合所有人的文档，所以我们更喜欢参考简洁的技术文档，而不是针对特定读者的扩展文章。</p>
<h2><a class="header" href="#api-documentation" id="api-documentation">API documentation</a></h2>
<h2><a class="header" href="#api文档" id="api文档">API文档</a></h2>
<h3><a class="header" href="#rand-crates" id="rand-crates">Rand crates</a></h3>
<p>建议使用 nightly Rust 来正确处理各种超链接。</p>
<p>要为 <a href="https://github.com/rust-random/rand">rust-random/rand</a> 代码库中的所有 crate 构建完整的API文档，请执行：</p>
<pre><code class="language-sh"># 为所有模块构建文档：
cargo doc --all --no-deps

# 打开文档链接
xdg-open target/doc/rand/index.html
</code></pre>
<p>在Linux上，很容易设置在做出任何编辑后自动重新构建：</p>
<pre><code class="language-sh">while inotifywait -r -e close_write src/ rand_*/; do cargo doc; done
</code></pre>
<p>编辑完API文档后，我们推荐测试了一些示例，并检查一下是否有坏链接：</p>
<pre><code class="language-sh">cargo test --doc

cargo install cargo-deadlinks
# 建议先把之前编译的剩余文件删除
rm -rf /target/doc
cargo doc --all --no-deps
cargo deadlinks --dir target/doc
</code></pre>
<p>Rand API文档被自动构建并托管在 <a href="../rand">rust-random.github.io/rand</a> 下。获取最新的代码可在 master 分支下获取。</p>
<h3><a class="header" href="#getrandom-crate" id="getrandom-crate">Getrandom crate</a></h3>
<p><a href="https://github.com/rust-random/getrandom">rust-random/getrandom</a> 代码库只包含了一个 crate，因此一个简单的 <code>cargo doc</code>命令就行了。</p>
<h3><a class="header" href="#cross-crate-links" id="cross-crate-links">Cross-crate links</a></h3>
<p>当链接另一个 crate 时，我们更喜欢链接到 crates.io 上的相应的 crate页面。因为(a)这里有记录板条箱用途的 README文件，(b)这些链接能直接链接到相应的代码库和API文档。示例：</p>
<pre><pre class="playground"><code class="language-rust">
<span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>// 链接到相应的 crate页面:：
//! [`rand_chacha`]: https://crates.io/crates/rand_chacha
<span class="boring">}
</span></code></pre></pre>
<p>当需要链接参考另一 crate 里的某个程序项时，</p>
<ol>
<li>如果该项可以通过 crate 依赖项（即使不是通过公共API）访问到时，则使用 Rust程序路径</li>
<li>当链接到 <code>rust-random/rand</code>代码库中的另一个 crate 时，可以使用生成的文档文件（<code>target/doc</code>下）中的相对路径；这些在 <a href="../rand">rust-random.github.io/rand</a> 上可行，但当前在 <code>docs.rs</code>网址下不行（参见<a href="https://github.com/rust-lang/docs.rs/issues/204">docs#204</a>）</li>
<li>如果以上两种都不适用，请使用绝对链接</li>
<li>考虑修改文件，例如以链接到 crate 来代替</li>
</ol>
<p>示例：</p>
<pre><code>// 我们依赖 rand_core，因此可以使用 Rust的路径：
/// [`BlockRngCore`]: rand_core::block::BlockRngCore

// rand_chacha不是一个依赖项，但在同一个代码库中：
//! [`ChaCha20Rng`]: ../../rand_chacha/struct.ChaCha20Rng.html

// 直接链接到 docs.rs，注意带上主版本号和小版本号，但补丁版本号不需要：
https://docs.rs/getrandom/0.1/getrandom/fn.getrandom.html
</code></pre>
<h2><a class="header" href="#auxilliary-documentation" id="auxilliary-documentation">Auxilliary documentation</a></h2>
<h2><a class="header" href="#辅助文档" id="辅助文档">辅助文档</a></h2>
<h3><a class="header" href="#readme-files" id="readme-files">README files</a></h3>
<h3><a class="header" href="#readme文件" id="readme文件">README文件</a></h3>
<p>README文件包含了对当前crate、盾牌徽章(shield badges)、有用链接、特性标志位的相关文档、许可证信息和潜在的示例的简要介绍。</p>
<p>在大多数情况下，本项目的文件没有任何持续的测试。在包含示例的地方（目前只针对 <code>rand_jitter</code> crate），我们通过 <code>doc_comment</code> 启用了持续测试（请参见 <a href="https://github.com/rust-random/rand/blob/master/rand_jitter/src/lib.rs#L62">lib.rs:62 onwards</a>）。</p>
<h3><a class="header" href="#changelog-files" id="changelog-files">CHANGELOG files</a></h3>
<h3><a class="header" href="#更新日志changelog文件" id="更新日志changelog文件">更新日志(CHANGELOG)文件</a></h3>
<p>更新日志的格式同 <a href="http://keepachangelog.com/en/1.0.0/">Keep a Changelog</a> 的格式要求保持一致。</p>
<p>自上次发布以来合并的所有重大更改都应该列在日志顶部的 <code>[Unreleased]</code>段落下面。</p>
<h3><a class="header" href="#the-book" id="the-book">The book</a></h3>
<h3><a class="header" href="#关于本书" id="关于本书">关于本书</a></h3>
<p>本书的源代码包含在 <a href="https://github.com/rust-random/book">rust-random/book</a>代码库中。它是使用 mdbook 构建的，这使得构建和测试都很容易：</p>
<pre><code class="language-sh">cargo install mdbook --version &quot;^0.2&quot;

mdbook build --open
mdbook test

# 任何更改后都自动重新构建：
mdbook watch
</code></pre>
<p>请注意，书中的链接是相对的，并且这些链接都被预先设定用于<a href="../book/">已发布上线的版本</a>。如果您在本地构建本书，您可能需要设置一个符号链接，以指向您构建的API文档：</p>
<pre><code class="language-sh">ln -s ../rand/target/doc rand
</code></pre>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                        
                            <a rel="prev" href="contributing.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                                <i class="fa fa-angle-left"></i>
                            </a>
                        

                        
                            <a rel="next" href="contrib-scope.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>
                        

                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">
                
                    <a rel="prev" href="contributing.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                        <i class="fa fa-angle-left"></i>
                    </a>
                

                
                    <a rel="next" href="contrib-scope.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
                
            </nav>

        </div>

        

        

        

        
        <script type="text/javascript">
            window.playground_copyable = true;
        </script>
        

        

        
        <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
        

        <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
        <script src="book.js" type="text/javascript" charset="utf-8"></script>

        <!-- Custom JS scripts -->
        

        

    </body>
</html>
